package com.greate.shiro.springbootshirodemo.service.impl;


import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.greate.shiro.springbootshirodemo.entity.SystemUserRole;
import com.greate.shiro.springbootshirodemo.mapper.SystemUserRoleMapper;
import com.greate.shiro.springbootshirodemo.service.SystemUserRoleService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author zs
 * @since 2020-07-28
 */
@Service
public class SystemUserRoleServiceImpl extends ServiceImpl<SystemUserRoleMapper, SystemUserRole> implements SystemUserRoleService {

	@Override
	public List<Integer> getRolesIdByUserId(Integer userId) {

		// 查询用户拥有的角色 id（所有的角色id）
		return lambdaQuery()
			.eq(SystemUserRole::getUserId, userId)
			.list()
			.stream()
			.map(SystemUserRole::getRoleId)
			.collect(Collectors.toList());
	}

}
